<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input type="text" placeholder="请输入手机号">
    <button>发送</button>
    <script>
        var but = document.querySelector('button')
        var time = 3;
        but.addEventListener('click', function () {
            var clears = setInterval(function () {
                if (time == 0) {
                    but.disabled = false
                    but.innerHTML = '发送'
                    //必须复原time值 不然定时器再次开始时 time值会为0 点击事件发生后会直接执行iftime=0的语句 这样逻辑顺序就错了
                    time = 3
                    clearInterval(clears)

                } else {
                    but.disabled = true
                    but.innerHTML = '还剩下' + time + '秒'
                    time--
                }
            }, 1000)
        })

    </script>
</body>

</html>